package cn.edu.cqut.mapper;

import java.util.List;

import org.apache.ibatis.annotations.Many;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.mapping.FetchType;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;

import cn.edu.cqut.entity.Customer;
import cn.edu.cqut.entity.DivideModel;
import cn.edu.cqut.entity.ReportModel;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author FeBro-TuoMei
 * @since 2020-06-18
 */
public interface CustomerMapper extends BaseMapper<Customer> {

	@Select("select count(*) value,cus_region item from customer group by cus_region")
	public List<ReportModel> selectCustomerCountByRegion(); 
	//将数据库里面的数据查询出来 返回给ReportModel
	
	@Select("select * from customer")
	@Results({
		@Result(column = "cus_no",property = "cusNo"),
		@Result(column = "cus_no",property = "contacts", 
				many = @Many(select = "cn.edu.cqut.mapper.ContactMapper.selectContactByCusNo",fetchType = FetchType.EAGER))
	})
	public List<Customer> selectCustomerWithContact();
	
	// 根据等级、信用度、满意度进行分组，用于画echars图
	@Select("SELECT ${searchInfo} name, count(*) value FROM customer  GROUP BY ${searchInfo}")
	public List<DivideModel> selectCustomerCountBySearchInfo(@Param("searchInfo") String searchInfo);
}
